let app = getApp();
Page({
  data: {
    nickName: "",
    userImage: "",
  },


  // 退出登录
  cancelLogin() {
    wx.showModal({
      title: "提示",
      content: "退出登录？",
      showCancel: true,
      cancelText: "不了",
      cancelColor: "#000000",
      confirmText: "确定",
      confirmColor: "#3CC51F",
      success: (result) => {
        if (result.confirm) {
          wx.removeStorageSync('cookie');
          wx.removeStorageSync('isLogin');
          wx.removeStorageSync('userId');
          wx.removeStorageSync('userInfo');
          this.setData({
            nickName: "",
            userImage: "",
          });
          // console.log(app)
          // 关闭连接
          app.globalData.sockTask.close()
        }
      },
    });
  },

  // 生命周期
  onLoad() {
    console.log("加载页面");

    if (wx.getStorageSync("isLogin")) {
      const userInfo = wx.getStorageSync("userInfo");
      this.setData({
        nickName: userInfo.nickName,
        userImage: userInfo.avatarUrl,
      });
    }
  },



  // 我的收藏
  handleCollect(){
    wx.navigateTo({
      url: '/pages/myCollect/myCollect',
    });
  },

  // 我的留言
  handleContent(){
    wx.navigateTo({
      url: '/pages/myContent/myContent',
    });
  },

  // 我的下单
  navToMyOrders(){
    wx.navigateTo({
      url: '/pages/myOrder/myOrder',
    });
  },

  //待处理订单
  navToPending(){
    wx.navigateTo({
      url: '/pages/myPending/myPending',
    });
  },

  // 我的发布
  handlePublish(){
    wx.navigateTo({
      url: '/pages/myPublish/myPublish',
    });
  }
});
